﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using IESN.DM;
using IESN.Communication;
using IESN.BusinessCore;
using IESN.BaseForms;

namespace IESN
{
    public partial class MainIES : XtraForm
    {
        private Controller _mController;

        /// <summary>
        /// 窗体上下文传递
        /// </summary>
        private AppContext _appContext=new AppContext();

        public MainIES()
        {
            InitializeComponent();
            this.WindowState = FormWindowState.Maximized; 
        }

        public MainIES(Controller theController):
            this()
        {
            _mController = theController;
        }

        #region 菜单事件

        #region 菜单事件-基础资料
       
        /// <summary>
        /// 用户程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniUserProgram_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            UserProgramFrm frmUP = new UserProgramFrm();
            frmUP.Show();
        }

        /// <summary>
        /// 流程管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniProcessManagement_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ProcessManagerFrm processEditFrm = new ProcessManagerFrm();
            processEditFrm.Show();
        }

        /// <summary>
        /// 系统设置及启动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniSysSetting_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SysSettingFrm frmSysSetting = new SysSettingFrm();
            frmSysSetting.Show();
        }

        ///// <summary>
        ///// 天车运行范围设置
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //private void btniTcarWorkRangeSetting_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        //{
        //    TcarWorkRangeSettingFrm frmTcarWRS = new TcarWorkRangeSettingFrm();
        //    frmTcarWRS.Show();
        //}

        /// <summary>
        /// 用户管理 权限
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUserManagement_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            UserManagementFrm frmUserManagement = new UserManagementFrm();
            frmUserManagement.Show();
        }
        #endregion

        #region 菜单事件-监控也设置

        /// <summary>
        /// 整流机监视
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniRectifierMonitor_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_appContext.GetForm("RectifierMonitorFrm") == null)
            {
                RectifierMonitorFrm frmRM = new RectifierMonitorFrm(_appContext);
                frmRM.Show();
            }
            else
            {
                
            }
        }

        /// <summary>
        /// 温度监视
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniTempMonitor_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_appContext.GetForm("TemperatureSettingFrm") == null)
            {
                TemperatureSettingFrm tempSettingFrm = new TemperatureSettingFrm(_appContext,_mController);
                tempSettingFrm.Show();
            }
            else
            {
                
            }
        }

        /// <summary>
        /// 药水自动添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniAutoAddMedicine_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            AutoAddMedicineFrm frmAutoAddMedicine = new AutoAddMedicineFrm();
            frmAutoAddMedicine.Show();
        }

        /// <summary>
        /// 药水维护
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniMedicineMaintain_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            MedicineInfoSettingFrm medicineInfoSettingFrm = new MedicineInfoSettingFrm();
            medicineInfoSettingFrm.Show();
        }

        /// <summary>
        /// 振动时间设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniVibrationTimeSetting_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_appContext.GetForm("VibrationTimeSettingFrm") == null)
            {
                VibrationTimeSettingFrm frmVibrationTimeSetting = new VibrationTimeSettingFrm(_appContext);
                frmVibrationTimeSetting.Show();
            }
            else
            {
                
            }
        }

        /// <summary>
        /// 电镀时间设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniElectroplateTimeSetting_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_appContext.GetForm("ElectroplateTimeSettingFrm")==null)
            {
                ElectroplateTimeSettingFrm electroplateTimeSettingFrm = new ElectroplateTimeSettingFrm(_appContext);
                electroplateTimeSettingFrm.Show();
            }
        }

        /// <summary>
        /// 天车运行步骤
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniTcarRuningStep_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            TcarRuningStepFrm frmTcarRuningStep = new TcarRuningStepFrm();
            frmTcarRuningStep.Show();
        }

        /// <summary>
        /// 输入资料 (上料时加载产品资料)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniLoadProductMaterialData_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LoadProductMaterialDataFrm frmLoadPMD = new LoadProductMaterialDataFrm();
            frmLoadPMD.Show();
        }

        /// <summary>
        /// 气振时间设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniAirVibrationTimeSetting_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //AirVibrationTimeSettingFrm frmAVTS = new AirVibrationTimeSettingFrm();
            //frmAVTS.Show();
        }

        #endregion

        #region 设备监控

        /// <summary>
        /// 天车状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniTcarStatus_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            TcarStatusFrm frmTcarStatus = new TcarStatusFrm();
            frmTcarStatus.Show();
        }

        #endregion

        #region 菜单事件-报告及查询

        /// <summary>
        /// 查询产品资料
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniQueryPuductMaterial_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            QueryPuductMaterialFrm frmQueryProductMaterial = new QueryPuductMaterialFrm();
            frmQueryProductMaterial.Show();
        }

        /// <summary>
        ///  产品生产次序查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniQueryProductProduceMaterial_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            QueryProductProduceMaterialFrm frmQueryProductProduceMaterial = new QueryProductProduceMaterialFrm();
            frmQueryProductProduceMaterial.Show();
        }

        /// <summary>
        /// 产量统计
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOutputiStatistics_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            OutputiStatisticsFrm frmOutputStatistics = new OutputiStatisticsFrm();
            frmOutputStatistics.Show();
        }

        /// <summary>
        /// 数据超界报告及操作记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniAlarmReport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            AlarmReportFrm frmAlarmReport = new AlarmReportFrm();
            frmAlarmReport.Show();
        }

        /// <summary>
        /// 天车故障编码手册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniTcarFaultCode_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            TcarFaultCodeFrm frmTcarFaultCode = new TcarFaultCodeFrm();
            frmTcarFaultCode.Show();
        }

        /// <summary>
        /// 设备报警报告
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniEquipmentAlarmReport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            EquipmentAlarmReportFrm frmEquipmentAlarmReport = new EquipmentAlarmReportFrm();
            frmEquipmentAlarmReport.Show();
        }

        #endregion

        #region 菜单事件-工具
        /// <summary>
        /// 登入登出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btniLoginoutForm_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //LoginoutFrm frmLoginoutFrom = new LoginoutFrm();
            //frmLoginoutFrom.Show();
        }

        #endregion

        private void MainIES_Load(object sender, EventArgs e)
        {
        }

        private void MainIES_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.ExitThread();
            Application.Exit();
        }

        #endregion

        private void btnProductLineStatus_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ProductLineStatusFrm plStatusFrm = new ProductLineStatusFrm();
            plStatusFrm.Show();
        }

        private void btnDmMapping_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DMMappingFrm dmMappingFrm = new DMMappingFrm();
            dmMappingFrm.Show();
        }

        private void btniTcarWorkRangeSetting_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            TcarWorkRangeSettingFrm tCarWorkRangeSettingFrm = new TcarWorkRangeSettingFrm();
            tCarWorkRangeSettingFrm.Show();
        }

        /// <summary>
        /// 产品资料维护
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnItemProductInfoSetting_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ProductMaterialInfoSettingFrm productMaterialInfoSettingFrm = new ProductMaterialInfoSettingFrm();
            productMaterialInfoSettingFrm.Show();
        }

        /// <summary>
        /// 测试通讯接口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCommTest_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            CommTestFrm commTestFrm = new CommTestFrm();
            commTestFrm.Show();
        }

        /// <summary>
        /// 参数设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnParameterSetting_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_appContext.GetForm("ParameterSettingFrm") == null)
            {
                ParameterSettingFrm parameterSettingFrm = new ParameterSettingFrm(_appContext,_mController);
                parameterSettingFrm.Show();
                
            }
            else
            {

            }

            
        }

    }
}
